package com.xc.h05.controller.changlongfei;

import com.xc.h05.entity.Course;
import com.xc.h05.entity.CourseCLF;
import com.xc.h05.entity.CourseCLF2;
import com.xc.h05.entity.CourseCLFV;
import com.xc.h05.service.changlongfei.VCourseService;
import com.xc.h05.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/vCourse")
public class VCourseController {

    @Autowired
    private VCourseService vCourseService;
    //    获取type分类
    @RequestMapping("/getType")
    public R getType(){
        return R.ok(vCourseService.getType());
    }
//    获取咨询师表
    @RequestMapping("/getConsult")
    public R getConsult(){
        return R.ok(vCourseService.getConsult());
    }
//    增加
    @PostMapping("/addCourse")
    public R addCourse(@RequestBody CourseCLF2 course){
        int i = vCourseService.addCourse(course);
        if (i==0){
            return R.ok("添加失败");
        }   else {
            return R.ok("添加成功");
        }

    }
//    删除
    @RequestMapping("/deleteCourse")
    public R deleteCourse(Long id){
        int i = vCourseService.deleteCourse(id);
        if (i==0){
            return R.ok("删除失败");
        }else {
            return R.ok("删除成功");
        }
    }
//    修改
    @PutMapping("/updateCourse")
    public R updateCourse(@RequestBody  CourseCLF2 course){
        int i = vCourseService.updateCourse(course);
        if (i==0){
            return R.ok("修改失败");
        }else {
            return R.ok("修改成功");
        }
    }
//    分页查询
    @RequestMapping("/getCourseByPage")
    public R getCourseByPage( @RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
                              @RequestParam(value = "pageSize", required = false, defaultValue = "20") int pageSize,
                              CourseCLFV courseCLFV){
        return R.ok(vCourseService.getCourseByPage(pageNum,pageSize,courseCLFV));
    }

//    批量删除
    @RequestMapping("/deleteCourseBatch")
    public R deleteCourseBatch(@RequestParam List<Long> ids){
        int i = vCourseService.deleteCourseBatch(ids);
        if (i==0){
            return R.ok("批量删除失败");
        }else {
            return R.ok("批量删除成功");
        }
    }

}
